package org.loon.game.sample.llk.Map.xml;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;


import org.loon.framework.javase.game.utils.xml.XMLDocument;
import org.loon.framework.javase.game.utils.xml.XMLElement;
import org.loon.framework.javase.game.utils.xml.XMLParser;



public class MapTools {

	public XMLDocument xmlDoc;
	// XMLElement xmlE;
	XMLParser xmlParer;

	public MapTools() {
		init();
	}

	private void init() {
		// xmlParer = new XMLParser();
		xmlDoc = XMLParser.parse("output.xml");
	}
	
	public ArrayList getLevelInfo(){
		XMLElement xmle = xmlDoc.getRoot();
		
		ArrayList<XMLElement>list = xmle.find("tile");
		
		XMLElement xmlRow=xmle.find("row").get(0);
		XMLElement xmlColm=xmle.find("colm").get(0);
		XMLElement xmlVGrid=xmle.find("allVisGrid").get(0);
		
		return list;
		
	}
	
	public int getGradNum(){
		XMLElement xmle = xmlDoc.getRoot();
		String c = xmle.find("allVisGrid").get(0).getContents();
		return Integer.valueOf(c);
	}
	
	public int getRow(){
		XMLElement xmle = xmlDoc.getRoot();
		String c = xmle.find("row").get(0).getContents();
		return Integer.valueOf(c);
	}
	
	public int getColm(){
		XMLElement xmle = xmlDoc.getRoot();
		String c = xmle.find("colm").get(0).getContents();
		return Integer.valueOf(c);
	}

	public static void main(String[] s) throws IllegalArgumentException,
			IllegalStateException, IOException {
		MapTools map = new MapTools();
		XMLElement xmle = map.xmlDoc.getRoot();

		XMLElement xmlRow = xmle.find("tile").get(0);
		//String aa = xmlRow.getAttribute("x").getValue();
		
		//XMLElement xmlRow=xmle.getChildrenByName("row");
		//System.out.println();
		//while (it.hasNext()) {
		System.out.println(xmlRow.getContents());
		//}

	}
}
